using System.IO;
using Budgeteer.Services;
using Budgeteer.Services.Common;
using WatiN.Core;
using Xunit;

namespace Test.UnitTests.Budgeteer.Services
{
    public class BankServiceFacts
    {
        public class Login
        {
            [Fact(Skip="IntegrationTest")]
            public void ShouldPassBankHomePageByClickingSignIn()
            {
                BankService bankService = new BankService();

                string url = "file://" + Path.Combine(Config.TestDataFolder,"BankDefaultPage.htm");

                using (IE ie = new IE(url))
                {
                    Assert.True(bankService.PassDefaultPage(ie));
                }
            }

            //[Fact]
            public void ShouldPassBankChallengePageByEnteringPassCode()
            {
                BankService bankService = new BankService();

                string url = "file://" + Path.Combine(Config.TestDataFolder,"BankChallengePage.htm");

                using(IE ie = new IE(url))
                {
                    Assert.True(bankService.PassChallengePage(ie));
                }
            }

            //[Fact]
            public void ShouldPassBalanceSheetPageByClickingOnCreditCardAccountLink()
            {
                BankService bankService = new BankService();

                string url = "file://" + Path.Combine(Config.TestDataFolder,"BankBalanceSheetPage.htm");

                using(IE ie = new IE(url))
                {
                    Assert.True(bankService.PassBalanceSheetPage(ie));
                }
            }

            //[Fact]
            public void ShouldPassAccountDetailPageBySelectingFileType()
            {
                BankService bankService = new BankService();

                string url = "file://" + Path.Combine(Config.TestDataFolder,"BankAccountDetailPage.htm");

                using(IE ie = new IE(url))
                {
                    Assert.True(bankService.PassAccountDetailPage(ie));
                }
            }

            //[Fact]
            public void ShouldPassAccountDetailExportByClickingContinueWithDownload()
            {
                BankService bankService = new BankService();

                string url = "file://" + Path.Combine(Config.TestDataFolder,"BankAccountDetailExportPage.htm");

                using(IE ie = new IE(url))
                {
                    Assert.True(bankService.PassAccountDetailExportPage(ie));
                }
            }

            //[Fact]
            public void ShouldHandleFileDownloadDialogBySavingFile()
            {
                BankService bankService = new BankService();

                string url = "file://" + Path.Combine(Config.TestDataFolder,"BankAccountDetailExportPage.htm");
                string saveToPath = Path.Combine(Config.TestDataFolder,"test.txt");

                 IE ie = new IE(url);
                {
                    Assert.True(bankService.SaveFile(ie,saveToPath));
                }
            }

            //[Fact]
            public void ShouldDownloadTransactionFile()
            {
                BankService bankService = new BankService();

                const string url = "https://www.bankofamerica.com/index.jsp";
                string saveToPath = Path.Combine(Config.TestDataFolder,"test.csv");

                bankService.DownloadTransactionFile(url,saveToPath);
            }
        }
    }
}